package com.cskaoyan.servlet;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.GoodsVo;
import com.cskaoyan.bean.vo.OrderVo;
import com.cskaoyan.bean.vo.StatGoodsVo;
import com.cskaoyan.bean.vo.StatVo;
import com.cskaoyan.service.StatService;
import com.cskaoyan.service.StatServiceimpl;
import com.cskaoyan.util.ResponseUtil;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author Ramsey
 * @date 2023年05月30日 13:09
 */
@WebServlet("/admin/stat/*")
public class AdminStatServlet extends WdBaseServlet {

    StatService statService = new StatServiceimpl();

    @SneakyThrows
    private void user(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("进入用户统计页面");
        List<Map> rows = statService.statUser();
        String[] columns = new String[]{"day", "users"};
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        ResponseUtil.responseOkJsonVo(response, statVo);
    }

    private BaseRespVo order(HttpServletRequest request, HttpServletResponse response) {

        return statService.statOrder();
    }

    @SneakyThrows
    private void goods(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("进入商品统计页面");
        List<Map> rows = statService.statGoods();
        String[] columns = new String[]{"day", "orders", "products", "amount"};
        StatGoodsVo statGoodsVo = new StatGoodsVo();
        statGoodsVo.setColumns(columns);
        statGoodsVo.setRows(rows);
        ResponseUtil.responseOkJsonVo(response, statGoodsVo);
    }


}
